Page({
  data: {
    nvabarData: {
      title: '',
      transmit: ''
    },
    data: {},
    videoSrc: '',
    videoTitle: '',
    viewCount: '',
    uploadDate: '',
    videoList: [
      {
        id: 1,
        title: '相关视频标题1',
        updateTime: '2025-10-30',
        viewCount: '8.7万',
        thumbnail: '/images/demo.jpeg',
        src: 'https://cdn.foruhealth.cn/fwf/video/3.mp4'
      },
      {
        id: 2,
        title: '相关视频标题2',
        updateTime: '2025-10-20',
        viewCount: '5.3万',
        thumbnail: '/images/demo.jpeg',
        src: 'https://cdn.foruhealth.cn/fwf/video/2.mp4'
      },
      {
        id: 3,
        title: '相关视频标题3',
        updateTime: '2024-05-20',
        viewCount: '9.1万',
        thumbnail: '/images/demo.jpeg',
        src: 'https://cdn.foruhealth.cn/fwf/video/1.mp4'
      }
    ]
  },

  onLoad: function (options) {
    const { item } = options;
    const data = JSON.parse(item)
    this.setData({
      'nvabarData.title': data.title
    })
    this.setData({
      data: data,
      videoSrc: data.videoSrc,
      viewCount: data.views,
      uploadDate: data.updateTime,
      videoTitle: data.title,
    })

    this.videoContext = wx.createVideoContext('myVideo')
    this.palyVideo()
  },

  switchVideo: function (e) {
    const video = e.currentTarget.dataset.video
    this.setData({
      videoSrc: video.src,
      videoTitle: video.title,
      viewCount: video.viewCount,
      uploadDate: video.updateTime,
    })

    this.videoContext.stop()
    this.palyVideo()
  },

  palyVideo() {
    if (this.timer) {
      clearTimeout(this.timer)
    }
    this.timer = setTimeout(() => {
      this.videoContext.play()
    }, 300)
  },
})